//
//  Team9ExpertFootCommentView.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/19.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9ExpertFootCommentView.h"
#import "Team9JQHeader.h"
//#import "Team9Header.h"
#import "Team9ExpertCommentModel.h"

@interface Team9ExpertFootCommentView ()

//@property(nonatomic, strong) UICollectionView *collectionView;
//@property(nonatomic, strong) UITableView *tableView;
// layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
@property(nonatomic, strong) Team9BaseView *myBackView;
@property(nonatomic, strong) Team9BaseLabel *nameLabel;
@property(nonatomic, strong) UIImageView *faceImageView;
@property(nonatomic, strong) UILabel *typeLabel;
@property(nonatomic, strong) Team9BaseLabel *summaryLabel;
@property(nonatomic, strong) Team9BaseLabel *timeLabel;


@end
@implementation Team9ExpertFootCommentView

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
//        [self test];
    }
    return self;
}
//- (void)test{
//    self.nameLabel.text = @"test";
//    self.typeLabel.text = @"test";
//    self.timeLabel.text = @"test";
//    self.summaryLabel.text = @"this is just a test for a coustom label font and frame. if not fit, we view chang it";
//    self.faceImageView.backgroundColor = [UIColor yellowColor];
//}
- (void)setModel:(Team9ExpertCommentModel *)model{
    if ( _model !=  model) {
        _model = model;
    }
    self.nameLabel.text = self.model.author_nick;
    switch (_model.author_type.intValue) {
        case 0:
            self.typeLabel.text = @"";
            break;
        case 1:
            self.typeLabel.text = @"设计师";
            break;
        case 2:
            self.typeLabel.text = @"工长";
        default:
            break;
    }
    self.summaryLabel.text = self.model.content;
    self.summaryLabel.numberOfLines = 0;
    [Team9Tool sd_imageView:self.faceImageView image:self.model.author_face placeholderImage:@"333"];
    self.timeLabel.text = self.model.create_time;
//    NSLog(@"%@", self.model.comment_parent_id);
    if (self.model.comment_parent_id.boolValue) {
        [self.faceImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.myBackView).offset(10);
            make.left.equalTo(self.myBackView).offset(10 + WIDTH / 375 * 40 + 20);            make.width.height.equalTo(@(40 * WIDTH / 375));
            [self.contentView updateConstraints];
        }];
    } else {
        [self.faceImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.myBackView).offset(10);
            make.width.height.equalTo(@(40 * WIDTH / 375));
            [self.contentView updateConstraints];
        }];
    }
    [Team9Tool imageView:self.faceImageView type:model.author_type Id:model.author_id viewController:self.vc];
    
}
- (void)createView{
    self.myBackView = [[Team9BaseView alloc] init];
    [self.contentView addSubview:self.myBackView];
    
    self.nameLabel = [[Team9BaseLabel alloc] initWith:LableColorTypeOrangeGreen];
    [self.contentView addSubview:self.nameLabel];
    
    self.faceImageView = [UIImageView new];
    [self.contentView addSubview:self.faceImageView];
    
    self.typeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_typeLabel];
    self.typeLabel.backgroundColor = [UIColor magentaColor];
    self.typeLabel.textColor = [UIColor whiteColor];
    
    self.summaryLabel = [[Team9BaseLabel alloc] init];
    [self.contentView addSubview:_summaryLabel];
    
    self.timeLabel = [[Team9BaseLabel alloc] init];
    [self.contentView addSubview:_timeLabel];
    
    
    self.nameLabel.font = [UIFont systemFontOfSize:14 * WIDTH / 375];
    self.typeLabel.font = [UIFont systemFontOfSize:12 * WIDTH / 375];
    self.summaryLabel.font = [UIFont systemFontOfSize:14 * WIDTH / 375];
    self.timeLabel.font = [UIFont systemFontOfSize:10 * WIDTH / 375];
    self.faceImageView.layer.cornerRadius = 20 * WIDTH / 375;
    self.faceImageView.layer.masksToBounds = YES;
    
    [self p_contraints];
}

- (void)p_contraints{
    [self.myBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.faceImageView.mas_centerY).offset(-5 * WIDTH / 375);;
        make.left.equalTo(self.faceImageView.mas_right).offset(10);
    }];
    
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nameLabel);
        make.left.equalTo(self.nameLabel.mas_right).offset(5);
    }];
    
    
    
    [self.summaryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.faceImageView.mas_centerY).offset(5 * WIDTH / 375);
        make.right.equalTo(self.myBackView).offset(-60 * WIDTH / 375);
        make.left.equalTo(self.nameLabel);
    }];
    
//    [self.faceImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.equalTo(self.myBackView).offset(10);
//        make.width.height.equalTo(@(40 * WIDTH / 375));
//    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.myBackView).offset(-10);
        make.top.equalTo(self.nameLabel);
    }];
    
    
}

@end
